#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
#include<set>
#include<map>

using namespace std;

int solve(int a, int b)
{
	if (b % 2 != 0)
	{
		return a;
	}
	else
	{
		return 0;
	}
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int a, b;
		cin >> a >> b;
		cout << solve(a, b) << endl;
	}
	return 0;
}